#include "../source/vlib.h"
#include <stdio.h>

static void test_create(void)
{
	queue_t queue = queue(int, 6);
	_queue(queue);
}

static void test_push_pop(void)
{
	queue_t queue = queue(int, 6);
	int data;
	
	for (int i = 0; i < 6; i++)
	{
		queue_push(queue, &i);
	}
	
	for (int i = 0; i < 6; i++)
	{
		if (queue_pop(queue, &data)) printf("pop %d\r\n", data);
	}
	
	_queue(queue);
}

static void test_at(void)
{
	queue_t queue = queue(int, 6);
	
	for (int i = 0; i < 6; i++)
	{
		queue_push(queue, &i);
	}
	
	for (int i = 0; i < 6; i++)
	{
		printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
	}
	
	_queue(queue);
}

static void test_insert(void)
{
	queue_t queue = queue(int, 6);
	
	for (int i = 0; i < 4; i++)
	{
		queue_push(queue, &i);
	}
	queue_insert(queue, 1, la(int, 1024), QUEUE_ORGIN_FRONT);
	
	for (int i = 0; i < queue_size(queue); i++)
	{
		printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
	}
	
	_queue(queue);
}

static void test_erase(void)
{
	queue_t queue = queue(int, 6);
	
	for (int i = 0; i < 4; i++)
	{
		queue_push(queue, &i);
	}
	queue_erase(queue, 1, 2, QUEUE_ORGIN_FRONT);
	
	for (int i = 0; i < queue_size(queue); i++)
	{
		printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
	}
	
	_queue(queue);
}

static void test_capacity(void)
{
	queue_t queue = queue(int, 6);
	
	for (int i = 0; i < 4; i++)
	{
		queue_push(queue, &i);
	}
	
	printf("capacity = %d\r\n", queue_capacity(queue));
	for (int i = 0; i < queue_size(queue); i++)
	{
		printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
	}
	
	printf("-------------------\r\n");
	
	queue_alter_capacity(queue, 8);
	printf("capacity = %d\r\n", queue_capacity(queue));
	
	queue_alter_capacity(queue, 3);
	printf("capacity = %d\r\n", queue_capacity(queue));
	
	for (int i = 0; i < queue_size(queue); i++)
	{
		printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
	}
	
	_queue(queue);
}

static void test_mode(void)
{
	queue_t queue = queue(int, 4);
	
	for (int i = 0; i < 4; i++)
	{
		queue_push(queue, &i);
	}
	
	for (int i = 0; i < queue_size(queue); i++)
	{
		printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
	}
	
	printf("push result: %d\r\n", queue_push(queue, la(int, 100)));
	printf("push result: %d\r\n", queue_push(queue, la(int, 1000)));
	
	queue_mode(queue, QUEUE_MODE_OVERWRITE, QUEUE_SET_MODE);
	
	printf("push result: %d\r\n", queue_push(queue, la(int, 100)));
	printf("push result: %d\r\n", queue_push(queue, la(int, 1000)));
	
	for (int i = 0; i < queue_size(queue); i++)
	{
		printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
	}
	
	_queue(queue);
}

static void test_init(void)
{
	QUEUE Q;
	int array[10];

	queue_init(&Q, array, sizeof(int), sizeof(array)/sizeof(array[0]));
	queue_deinit(&Q);
}

void test_queue(void)
{
	// test_create();
	// test_push_pop();
	// test_at();
	// test_insert();
	// test_erase();
	// test_capacity();
	// test_mode();
	test_init();
}